/*zhaoyihang
 * 连接sql
 * */

#include "threadPool.h"

MYSQL* mysqlConnect(const char* mysqlUserName,const char* mysqlUserPass)
{
    //创建子线程前，主线程先连接上sql
    MYSQL *mysql;
    //声明sql的锁
    pthread_mutex_t mysql_mutex;
    //初始化锁
    pthread_mutex_init(&mysql_mutex, NULL);
    //初始化sql
    mysql = mysql_init(NULL);
    if (mysql == NULL) {
        fprintf(stderr, "mysql_init() failed\n");
        exit(1);
    }
    //建立mysql链接
    MYSQL * ret = mysql_real_connect(mysql,"localhost",mysqlUserName,mysqlUserPass,"MyLuminaryDrive",0,NULL,0);
    if(ret == NULL){
        fprintf(stderr,"mysql connect error:%s\n", mysql_error(mysql));
        exit(1);
    }
    return  mysql;
}
